package com.tal.pad.orc.base.net;

import com.tal.bcc.pad.cloud.CloudUploadBusiness;
import com.tal.bcc.pad.cloud.config.CloudConfig;
import com.tal.bcc.pad.cloud.entity.CloudDir;
import com.tal.bcc.pad.cloud.entity.CloudResult;
import com.tal.bcc.pad.cloud.entity.CloudUploadEntity;
import com.tal.bcc.pad.cloud.listener.StsUploadListener;
import com.tal.pad.orc.base.AppConfig;
import com.tal.pad.orc.base.utils.LogUtils;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Response;

import java.io.IOException;


public class ImageUtils {

    public static final String TAG = ImageUtils.class.getSimpleName();


    public void uploadImgToOss(String path,boolean isChangeOssURL) {
        CloudUploadBusiness xesCloudUploadBusiness = new CloudUploadBusiness();
        CloudUploadEntity uploadEntity = new CloudUploadEntity();
        uploadEntity.setFilePath(path);
        uploadEntity.setType(CloudConfig.UPLOAD_IMAGE);
        uploadEntity.setLoadOSSBackupHost(isChangeOssURL);
        uploadEntity.setCloudPath(AppConfig.DEBUG ? CloudDir.CLOUD_TEST : CloudDir.COMMON);

        xesCloudUploadBusiness.asyncUpload(uploadEntity, new StsUploadListener() {
            @Override
            public void onProgress(CloudResult cloudResult, int i) {

            }

            @Override
            public void onSuccess(CloudResult cloudResult) {
                String httppath = cloudResult.getHttpPath();
                 System.out.println("path: "+path + "上传oss成功，imageUrl=" + httppath);
//                LogUtils.getLogUtils().info(TAG, "path: "+path + "上传oss成功，imageUrl=" + httppath);
//                if (mListerer != null) {
//                    mListerer.onSuccess(httppath);
//                }
            }

            @Override
            public void onError(CloudResult cloudResult) {
//                if (retryCount < 1){
//                    retryCount++;
//                    uploadImgToOss(path,false);
//                }else if (retryCount< RETRY_COUNT){
//                    retryCount++;
//                    uploadImgToOss(path,true);
//                } else {
                LogUtils.getLogUtils().info(TAG, "onError 图片上传失败大于3次：" + (cloudResult.getErrorMsg()==null?"":cloudResult.getErrorMsg()));
//                    if (mListerer != null) {
//                        mListerer.onError(ERROR_TYPE_UPLOAD_ERROR, "图片上传失败，请检查网络再试");
//                    }
//                }
            }
        });
    }
}
